package com.three.iot.commons.enums;

import java.util.Objects;

/**
 * @author luiz
 * @Title: ResultCode
 * @ProjectName iot
 * @Description: 设备状态类型枚举
 * @date 2019-04-03 16:00
 */
public enum IotDeviceStatusEnum {
    ONLINE("ONLINE", "在线"),
    OFFLINE("OFFLINE", "离线"),
    UNACTIVE("UNACTIVE", "未激活"),
    DISABLE("DISABLE", "已禁用"),
    ;
    String code;
    String name;

    IotDeviceStatusEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(String code) {
        IotDeviceStatusEnum iotDeviceStatusEnum=matching(code);
        if(iotDeviceStatusEnum!=null){
            return iotDeviceStatusEnum.getName();
        }
        return "";
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static final IotDeviceStatusEnum matching(String code) {
        for (IotDeviceStatusEnum iotDeviceStatusEnum : IotDeviceStatusEnum.values()) {
            if (Objects.equals(iotDeviceStatusEnum.getCode(), code)) {
                return iotDeviceStatusEnum;
            }
        }
        return null;
    }
}
